package etm;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import etm.test.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that StrafeNShoot always
 * beats SittingDuck.
 * 
 * @author Philip Johnson, Modified: Edward Meyer
 */
public class TestStrafeNShootVersusCorners extends RobotTestBed {

  /**
   * Specifies that SittingDuck and StrafeNShoot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Corners,etm.StrafeNShoot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The actual test, which asserts that StrafeNShoot has won every round against Corners.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] results = event.getIndexedResults();
    // Sanity check that results[1] is StrafeNShoot (not strictly necessary,
    // but illustrative).
    assertEquals("Check results[1]", results[1].getTeamLeaderName(), "etm.StrafeNShoot");

    // Check to make sure StrafeNShoot more than half of the total rounds
    assertTrue("Check that we win at least half the time against Walls",
        (results[1].getFirsts() >= getNumRounds() / 2));

  }
}
